package com.dnjn.happiness.common.config.jackson;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class LongJacksonSerializer extends JsonSerializer<Long> {

    public static final double MAX_JS_LONG = Math.pow(2, 53);
    public static final LongJacksonSerializer instance = new LongJacksonSerializer();
    @Override
    public void serialize(Long value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        if(value >= MAX_JS_LONG){//todo
            String text = (value == null ? null : String.valueOf(value));
            if (text != null) {
                jsonGenerator.writeString(text);
            }
            return;
        }else {
            jsonGenerator.writeNumber(value);
        }
    }

    public static void main(String[] args) {
        System.out.println(Math.pow(2,53));
    }
}
